# import mediapipe as mp
# import cv2
#
# mp_drawing = mp.solutions.drawing_utils
# mp_holistic = mp.solutions.holistic
# # 获取到摄像头的使用权
# cap = cv2.VideoCapture(0)
# with mp_holistic.Holistic(min_tracking_confidence=0.8, min_detection_confidence=0.8) as holistic:
#     # 摄像头是否打开
#     while cap.isOpened():
#         # 从摄像头读取一帧图像
#         ret, frame = cap.read()
#         frame = cv2.flip(frame, 1)
#         img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
#         results = holistic.process(img)
#         # print(results.pose_landmarks)
#         # 绘制检测点
#         img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
#         # 绘制脸部检测点
#         # mp_drawing.draw_landmarks(img, results.face_landmarks, mp_holistic.FACEMESH_CONTOURS)
#         # mp_drawing.draw_landmarks(img, results.poce_landmarks, mp_holistic.POSE_CONNECTIONS)
#         # 右手
#         mp_drawing.draw_landmarks(img, results.right_hand_landmarks, mp_holistic.HAND_CONNECTIONS)
#         # 左手
#         mp_drawing.draw_landmarks(img, results.left_hand_landmarks, mp_holistic.HAND_CONNECTIONS)
#         # 肢体
#         mp_drawing.draw_landmarks(img, results.pose_landmarks, mp_holistic.POSE_CONNECTIONS)
#         # 显示图像
#         print(results.right_hand_landmarks)
#         cv2.imshow('img', img)
#         # 按下 q 退出
#         if cv2.waitKey(10) and 0xFF == ord('q'):
#             break
# # 释放摄像头资源
# cap.release()
# # 关闭所有窗口
# cv2.destroyAllWindows()

import cv2
import mediapipe as mp
mp_drawing = mp.solutions.drawing_utils
mp_holistic = mp.solutions.holistic
img = cv2.imread('images/demo.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

with mp_holistic.Holistic(min_tracking_confidence=0.5, min_detection_confidence=0.5) as holistic:

    results = holistic.process(img)
    img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
    mp_drawing.draw_landmarks(img, results.pose_landmarks, mp_holistic.POSE_CONNECTIONS)
    print(results.pose_landmarks)
    cv2.imshow('img', img)

if cv2.waitKey() == ord('q'):
    cv2.destroyAllWindows()


"""
检测视频中的人物，真人
"""
# import cv2
# import mediapipe as mp
#
# mp_holistic = mp.solutions.holistic
# mp_drawing = mp.solutions.drawing_utils
# cap = cv2.VideoCapture('images/跳舞视频.mp4')
# with mp_holistic.Holistic(min_tracking_confidence=0.5, min_detection_confidence=0.5) as holistic:
#     while cap.isOpened():
#         success, img = cap.read()
#         img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
#         results = holistic.process(img)
#         img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
#         # 绘制大致形态
#         mp_drawing.draw_landmarks(img, results.pose_landmarks, mp_holistic.POSE_CONNECTIONS)
#         w, h, z = img.shape
#         img = cv2.resize(img, (h // 2, w // 2))
#         cv2.imshow('video', img)
#         if cv2.waitKey(1) == ord('q'):
#             break
# cap.release()
# cv2.destroyAllWindows()
